package com.zcn.io.web.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcn.io.common.util.DateUtil;
import com.zcn.io.web.api.entity.ThawInfo;
import com.zcn.io.web.api.vo.ThawInfoVo;
import com.zcn.io.web.auth.LoginUser;
import com.zcn.io.web.mapper.ThawInfoMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:
 * @author: 202438 邱建伟
 * @date: 2025/1/12 14:00
 * @Copyright (c) 2025, 江苏金恒信息科技股份有限公司
 */
@Service
@RequiredArgsConstructor
public class ThawInfoService {

    private final ThawInfoMapper thawInfoMapper;

    public void list(Page<ThawInfo> page, ThawInfo negotiateInfo) {
        this.thawInfoMapper.list(page, negotiateInfo);
    }

    public void save(ThawInfo negotiateInfo) {
        negotiateInfo.setLastHandleTime(DateUtil.getDefaultDate());
//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        if (principal instanceof LoginUser) {
//            negotiateInfo.setLastHandleUser(((LoginUser) principal).getUsername());
//        }
        this.thawInfoMapper.insert(negotiateInfo);
    }

    public ThawInfo getById(String id) {
        return thawInfoMapper.selectById(id);
    }

    public void updateById(ThawInfo negotiateInfo) {
        negotiateInfo.setLastHandleTime(DateUtil.getDefaultDate());
//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        if (principal instanceof LoginUser) {
//            negotiateInfo.setLastHandleUser(((LoginUser) principal).getUsername());
//        }
        thawInfoMapper.updateById(negotiateInfo);
    }

    public void deleteById(String id) {
        thawInfoMapper.deleteById(id);
    }

    public List<ThawInfoVo> listAllByPhoneCode(ThawInfo thawInfo) {
        return thawInfoMapper.listAllByPhoneCode(thawInfo);
    }
}
